package com.test.demo.consumer;

import com.test.demo.dao.pojo.OrderPaid;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

/**
 * RocketMQ消费者有2种消费模式，广播和轮询
 * BROADCASTING("BROADCASTING"),
 * CLUSTERING("CLUSTERING");
 * 集群消费（Clustering）：集群消费模式下，相同 Consumer Group 的每个 Consumer 实例平均分摊消息。
 *
 * consumeMode中如果想要消费者顺序消费，则 ConsumeMode.ORDERLY
 * 否则还是乱序消费 ConsumeMode.CONCURRENTLY
 * @author Gao
 */
@Slf4j
@Service
@RocketMQMessageListener(consumeMode = ConsumeMode.CONCURRENTLY, topic = "tx-text-topic",
        consumerGroup = "my-consumer_tx-text-topic", messageModel = MessageModel.CLUSTERING)
public class TxConsumer implements RocketMQListener<OrderPaid> {

    @Override
    public void onMessage(OrderPaid message) {
        log.info("消费端接收到事务消息：{}", message.toString());
    }
}
